package com.bl.student.manager.controller.address;

import com.bl.student.common.ApiResponseBody;
import com.bl.student.common.utils.UUIDUtils;
import com.bl.student.manager.controller.BaseController;
import com.bl.student.service.biz.address.AddressService;
import com.bl.student.service.vo.address.AddressAddVo;
import com.bl.student.service.vo.address.AddressModVo;
import com.bl.student.service.vo.address.AddressVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;
import com.bl.student.service.vo.DelBody;
import com.bl.student.service.vo.DelListBody;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * Created by liangweikang on 18/1/29.
 */
@RestController
@Log4j2
@RequestMapping(value = {"/student/manager/address"})
@Api(value = "地址", description = "地址相关api")
public class AddressController extends BaseController {

    @Autowired
    AddressService addressService;

    @ApiOperation(value = "增加地址信息", notes = "增加地址信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/add"})
    public ApiResponseBody add(
            @Valid @RequestBody AddressAddVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }
        addressService.add(body, UUIDUtils.getUUID());
        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "修改地址信息", notes = "修改地址信息 ")
    @ApiImplicitParams({})
    @PostMapping(value = {"/modify"})
    public ApiResponseBody modify(
            @Valid @RequestBody AddressModVo body, BindingResult result,
            HttpServletRequest request) {

        ApiResponseBody validResult = validParams(result);
        if (validResult != null) {
            return validResult;
        }
        addressService.modify(body);
        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "查询用户地址信息", notes = "查询地址信息 ")
    @ApiImplicitParams({})
    @GetMapping(value = {"/get_detail"})
    public ApiResponseBody<AddressVo> getAddressVo(
            HttpServletRequest request) {

        String partybId = "187ce59a14be48ea8e550e4299c9642d";
        AddressVo addressVo = addressService.getAddressVo(partybId);
//        AddressVo addressVo = addressService.getAddressVo(getUserInfo(request).getId());


        return ApiResponseBody.createSuccessBody(addressVo);
    }


    @ApiOperation(value = "删除单个地址", notes = "删除单个地址 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del"})
    public ApiResponseBody del(
            @Valid @RequestBody DelBody body, BindingResult result,
            HttpServletRequest request) {

        addressService.del(body);

        return ApiResponseBody.createSuccessBody(null);
    }

    @ApiOperation(value = "删除批量地址", notes = "删除批量地址 ")
    @ApiImplicitParams({
    })
    @PostMapping(value = {"/del_list"})
    public ApiResponseBody delList(
            @Valid @RequestBody DelListBody body, BindingResult result,
            HttpServletRequest request) {

        addressService.delList(body);

        return ApiResponseBody.createSuccessBody(null);
    }

}
